<#import "../../../common/layout.ftl" as l>


<@l.content>



<script>

    var shipId = '<#if shipInfo??>${shipInfo.shipid}</#if>';
    var crud = {
        read: "/manage/ship/manning/detail",
        update: '/manage/ship/manning/update',
        del: "/manage/ship/manning/delete"
    };

    var model = [
        {name : 'id',type : 'hidden',text : '编号',allowBlank : true,primaryKey : true},
        {name : 'shipid',type : 'select',text : '船舶',value:shipId,allowBlank : false,primaryKey : false,options : {
            url : "/manage/ship/ajax/list",
            displayField : "shipName",
            valueField : "shipid"
        }},
        {name : 'manningName',type : 'text',text : '配员姓名',allowBlank : false,primaryKey : false},
        {name : 'mainningDuty',type : 'text',text : '配员职务',allowBlank : false,primaryKey : false},
        {name : 'recordBookId',type : 'text',text : '服务簿编号',allowBlank : false,primaryKey : false},
        {name : 'competencyCertify',type : 'text',text : '适任证号码',allowBlank : false,primaryKey : false},
        {name : 'serviceTime',type : 'date',text : '任职时间',allowBlank : false,primaryKey : false},
        {name : 'boatServiceTime',type : 'date',text : '上船时间',allowBlank : false,primaryKey : false},
        {name : 'emergencyContact',type : 'text',text : '紧急联系人',allowBlank : false,primaryKey : false},
        {name : 'emergencyContactNumber',type : 'text',text : '紧急联系人号码',allowBlank : false,primaryKey : false}
    ];
</script>


<form id="pagination-form" method="post">
    <input type="hidden" name="shipid" value="<#if param.shipid??>${param.shipid}<#else></#if>">
    <input type="hidden" name="page" value="${pageInfo.pageNum}">
    <input type="hidden" name="limit" value="${pageInfo.pageSize}">
    <input type="hidden" name="totalPage" value="${pageInfo.pages}">
    <div class="ibox">
        <div class="ibox-title">
            <h5>配员信息<#if shipInfo.shipName??>-${shipInfo.shipName}<#else></#if></h5>

            <div class="ibox-tools">
                <a href="/manage/ship/list" >
                    <i class="fa fa-reply"></i>
                    返回
                </a>
                <a href="#" id="pagination-add">
                    <i class="fa fa-plus"></i>
                    添加
                </a>
                <a id="pagination-edit" href="#">
                    <i class="fa fa-edit"></i>
                    编辑
                </a>

                <a id="pagination-delete" href="#">
                    <i class="fa fa-trash"></i>
                    删除
                </a>

            </div>
        </div>
        <div class="ibox-content">
            <div class="input-group search-content">
                <input type="text" name="shipName" value="<#if param.shipName??>${param.shipName}<#else></#if>" class="form-control"> <span class="input-group-btn">
                <input type="submit" class="btn btn-primary" value="搜索">
            </span></div>
            <div>
                <div class="table-responsive">
                    <table class="table table-striped table-hover dataTables-example" >
                        <thead>
                        <tr>
                            <th>&nbsp;</th>
                            <th>配员姓名</th>
                            <th>配员职务</th>
                            <th>服务簿编号</th>
                            <th>适任证号码</th>
                            <th>任职时间</th>
                            <th>上船时间</th>
                            <th>紧急联系人</th>
                            <th>紧急联系人号码</th>
                            <th>手机端账号</th>
                        </tr>
                        </thead>

                        <tbody>
                            <#list pageInfo.list as report>
                            <tr>
                                <td><input type="checkbox" class="i-checks" value="<#if report.id??>${report.id}<#else></#if>"></td>
                                <td><a href="#" onclick="pagination.editItem('<#if report.id??>${report.id}<#else></#if>')"><#if report.manningName??>${report.manningName}<#else></#if></a></td>
                                <td><#if report.mainningDuty??>${report.mainningDuty}<#else></#if></td>
                                <td><#if report.recordBookId??>${report.recordBookId}<#else></#if></td>
                                <td><#if report.competencyCertify??>${report.competencyCertify}<#else></#if></td>
                                <td><#if report.serviceTime??>${report.serviceTime}<#else></#if></td>
                                <td><#if report.boatServiceTime??>${report.boatServiceTime}<#else></#if></td>
                                <td><#if report.emergencyContact??>${report.emergencyContact}<#else></#if></td>
                                <td><#if report.emergencyContactNumber??>${report.emergencyContactNumber}<#else></#if></td>
                                <td><#if report.userId??><a href="#" onclick="removeUserAccount('${report.id}')">${report.userId}</a><#else><a href="#" onclick="addMobileAccount('${report.id}')">分配</a></#if></td>
                            </tr>
                            </#list>
                        </tbody>


                    </table>
                </div>
                <div class="pagination-content">
                    <div id="pagination" class="pagination">
                    </div>
                </div>
            </div>
        </div>

    </div>
</form>


</@l.content>

<script>
    function removeUserAccount(id) {
        layerConfirm("是否移除该账号?",{},function () {
            $.get("/manage/ship/manning/removeMobileAccount",{id:id},function (result) {
                location.reload();
            })
        })
    }


    function addMobileAccount(id) {
        layer.open({
            type: 1 //此处以iframe举例
            ,title: '设置手机端账号'
            ,area: ['390px', '330px']
            ,shade: '#fff'
            ,content: '<form action="/manage/ship/manning/setMobileAccount" method="post" id="setMobileAccountForm" class="form-horizontal"><input type="hidden" name="id" value="'+id+'">'
            + '<div class="form-group" style="margin: 30 0">'
            + '<label class="col-sm-3 control-label">账号</label>'
            + '<div class="col-sm-7"><select id="setMobileAccountFormSelect" class="form-control chosen-select" name="userId">'
            + '</select></div>'
            + '</div>'
            +'</form>'
            ,btn: ['确定', '关闭']
            ,yes: function(){
                var form = $("#setMobileAccountForm");
                form.ajaxSubmit(function (data) {
                    location.reload();
                })
            }
//            ,btn2: function(){
//                layer.closeAll();
//            }

            ,zIndex: layer.zIndex //重点1
        });

        $.get("/manage/ship/user/ajax/list",{},function (result) {
            $("#setMobileAccountFormSelect").html("");
            for(var i = 0; i < result.length ; i++){
                var data = result[i];
                $("#setMobileAccountFormSelect").append("<option value='"+data.loginName+"'>"+data.loginName +" | "+data.ship.shipName+"</option>");
            }
//            $(".chosen-select").chosen({});
        })
    }
</script>

<script src="/pagination/js/pagination.js"></script>
